package com.aliyun.messagemgt.repository;


import com.aliyun.messagemgt.converter.SmsQuotaMonitorConverter;
import com.aliyun.messagemgt.dto.SmsQuotaMonitor;
import com.aliyun.messagemgt.domain.repository.SmsQuotaMonitorRepository;
import com.aliyun.messagemgt.entities.SmsQuotaMonitorEntity;
import com.aliyun.messagemgt.repository.mappers.SmsQuotaMonitorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Description
 * @Author hzw
 * @Date 2020/12/15 15:21
 * @Version 1.0
 */
@Service
public class SmsQuotaMonitorMybatisRepository implements SmsQuotaMonitorRepository {
    @Autowired
    private SmsQuotaMonitorMapper smsQuotaMonitorMapper;

    /**
     * 插入监控记录
     *
     * @param smsQuotaMonitor 短信配额监控信息
     */
    @Override
    public void insert(SmsQuotaMonitor smsQuotaMonitor) {

        smsQuotaMonitorMapper.insert(smsQuotaMonitor);
    }

    /**
     * 更新短信配额监控记录
     *
     * @param smsQuotaMonitor 短信配额监控信息
     */
    @Override
    public void update(SmsQuotaMonitor smsQuotaMonitor) {
        smsQuotaMonitorMapper.update(smsQuotaMonitor);
    }

    /**
     * 删除
     *
     * @param msgSourceId 消息源uuid
     */
    @Override
    public void delete(String msgSourceId) {
        smsQuotaMonitorMapper.delete(msgSourceId);
    }

    /**
     * 根据消息源id和状态查询短信配额监控信息
     *
     * @param msgSourceId 消息源UUID
     * @param status      状态
     * @return 监控信息
     */
    @Override
    public SmsQuotaMonitor selectMonitorByMsgSourceIdAndStatus(String msgSourceId, Integer status) {
        SmsQuotaMonitorEntity smsQuotaMonitorEntity = smsQuotaMonitorMapper.selectMonitorByMsgSourceIdAndStatus(msgSourceId, status);
        SmsQuotaMonitor smsQuotaMonitor = SmsQuotaMonitorConverter.INSTANCE.smsQuotaMonitorEntity2smsQuotaMonitor(smsQuotaMonitorEntity);
        return smsQuotaMonitor;
    }
}
